package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;


    @RequestMapping("/checkitem/findPage")
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public PageResult findAll(@RequestBody QueryPageBean queryPageBean) {
        return checkItemService.findAll(queryPageBean);
    }

    // /checkitem/findAll 查询所有的检查项信息
    @RequestMapping("/checkitem/findAll")
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public PageResult findAllCheckitem(@RequestBody QueryPageBean queryPageBean){
        return checkItemService.findAll(queryPageBean);
    }

    //新增 检查项
    @RequestMapping("/checkitem/add")
    @PreAuthorize("hasAuthority('CHECKITEM_ADD')")
    // 不加 @RequestBody  不会封转进 CheckItem 的对象中

    public Result add(@RequestBody CheckItem checkItem) {
        return checkItemService.add(checkItem);

    }

    //  /checkitem/findById.do
    @RequestMapping("/checkitem/findById")
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public Result findById(String id){
        return checkItemService.findById(Integer.parseInt(id));
    }

    // /checkitem/edit
    @RequestMapping("/checkitem/edit")
    @PreAuthorize("hasAuthority('CHECKITEM_EDIT')")
    public Result edit(@RequestBody CheckItem checkItem) {
        return checkItemService.update(checkItem);
    }

    // /checkitem/delete
    @RequestMapping("/checkitem/delete")
    @PreAuthorize("hasAuthority('CHECKITEM_DELETE')")
    public Result delete(String id){
        return checkItemService.delete(Integer.parseInt(id));
    }

}
